<?php
/**
 * 发货单自动拉取运单号
    1、按发货单生成时间排序
    2、限定生成时间30分钟以前，防止有取消操作导致回收运单号
 * @author liuhua@leemanpaper.com
 * @version $20180524
 */
$domain = $argv[1];

if (empty($domain)) {
    die('No Params');
}
set_time_limit(0);
require_once(dirname(__FILE__) . '/../../lib/init.php');
cachemgr::init(false);
$_SERVER['HTTP_HOST'] = $domain;

try{
    $create_time= time()-1800;
    $db = kernel::database();
    $sql = 'SELECT A.delivery_id,B.channel_id,A.delivery_bn,E.`name` branchname,F.`name` shopname,F.shop_type FROM sdb_wms_delivery A inner join sdb_ome_dly_corp B on A.logi_id=B.corp_id inner join sdb_wms_delivery_bill C on A.delivery_id=C.delivery_id inner join sdb_ome_branch E on A.branch_id=E.branch_id inner join sdb_ome_shop F on A.shop_id=F.shop_id WHERE A.type="normal" AND (A.print_status & 4) !=4 and A.status=0 and E.`owner`=1 and process_status in(0,1) and A.disabled="false"  and C.type=1 and C.status=0 and C.logi_no is null and is_form="true" and deliverytype!="pickup" and B.channel_id is not null and A.create_time<'.$create_time.' limit 0,100';
   
    $deliverys = $db->select($sql);
    foreach ($deliverys as $key => $value)
    {
        $result = kernel::single('wms_event_trigger_logistics_electron')->directGetWaybill($value['delivery_id'], $value['channel_id']);
        error_log(date('Y-m-d H:i:s').'-'.$key.'开始'.$value['delivery_id'].'-'.$value['channel_id'].'【'.json_encode($result)."】".PHP_EOL, 3, DATA_DIR.'/logs/autogetWaybillLogiNo'.date('Y-m-d').'.log');
    }

}catch (Exception $e) 
{
    error_log(date('Y-m-d H:i:s') . '发送数据/' . var_export($e->getMessage(), true), 3, PUBLIC_DIR.'/logs/autogetWaybillLogiNo'.date('Y-m-d').'.log');
}


